using System;
using System.Xml;
using System.IO;

using Icodeon;

using NUnit.Framework;

namespace Icodeon.Util
{
    [TestFixture]
    public class ScormUtilsTest : BaseTest
    {
        [TestFixtureSetUp]
        public void Init()
        {
            this.SetUp();
        }

        [TestFixtureTearDown]
        public void Dispose()
        {
        }

        [Test]
        public void TestGetScormVersion()
        {
            try
            {
                ScormUtils scormUtils = new ScormUtils();
                Assert.AreEqual(ScormVersion.scorm1p2, scormUtils.GetScormVersion(this.manifest));
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                Assert.Fail(e.Message);
            }

        }

        [Test]
        public void TestGetScormType()
        {
            try
            {

                XmlUtils xmlUtils = new XmlUtils();
                XmlElement resources = xmlUtils.GetNamedChildElement(this.manifest, "resources");
                Assert.IsNotNull(resources);
                XmlElement resource = xmlUtils.GetNamedChildElement(resources, "resource");
                Assert.IsNotNull(resource);

                ScormUtils scormUtils = new ScormUtils();
                ScormVersion scormVersion = scormUtils.GetScormVersion(this.manifest);
                Assert.AreEqual(ScormVersion.scorm1p2, scormVersion);
                ScormType scormType = scormUtils.GetScormType(resource, scormVersion);
                Assert.AreEqual(ScormType.sco, scormType);
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                if (e.InnerException != null)
                {
                    System.Console.WriteLine(e.InnerException.Message);
                }
                System.Console.WriteLine(e.StackTrace);
                Assert.Fail(e.Message);
            }

        }
    }
}
